package com.example.pojo.dao;
import com.example.pojo.entity.PostIndex;
import org.springframework.data.elasticsearch.annotations.Highlight;
import org.springframework.data.elasticsearch.annotations.HighlightField;
import org.springframework.data.elasticsearch.annotations.HighlightParameters;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description TODO..
 * @Author: kevin
 * @Date: 2023-10-18
 */
@Repository
public interface PostIndexRepository extends ElasticsearchRepository<PostIndex, Integer> {
    /**
     * 查询内容标题查询
     * @param posName 职位名称
     * @param
     * @return 返回关键字高亮的结果集
     */
    @Highlight(
            //字段
            fields = {@HighlightField(name = "posName"),@HighlightField(name = "companyName"),@HighlightField(name = "posDescription")},
            parameters = @HighlightParameters(preTags = {"<span style='color:red;font-weight: bold;'>"}, postTags = {"</span>"}, numberOfFragments = 5)
    )
//    @Query("{\"bool\": {\"should\": [{\"fuzzy\": {\"field1\": {\"value\": \"?0\", \"fuzziness\": 2}}}, {\"fuzzy\": {\"field2\": {\"value\": \"?0\", \"fuzziness\": 2}}}]}}")
//    @Query("{\"bool\": {\"should\": [{\"fuzzy\": {\"pos_name\": {\"value\": \"?0\", \"fuzziness\": 2}}}, {\"fuzzy\": {\"company_name\": {\"value\": \"?1\", \"fuzziness\": 2}}}]}}")
    List<SearchHit<PostIndex>> findByPosNameOrCompanyNameOrPosDescription(String posName,String companyName,String posDescription);



//    @Highlight(
//            //字段
//            fields = {@HighlightField(name = "search")},
//            parameters = @HighlightParameters(preTags = {"<span style='color:red;font-weight: bold;'>"}, postTags = {"</span>"}, numberOfFragments = 5)
//    )
//    List<SearchHit<PostIndex>> findByPosNameOrCompanyName(String search);


    @Highlight(
            //字段
            fields = {@HighlightField(name = "posDescription")},
            parameters = @HighlightParameters(preTags = {"<span style='color:red;font-weight: bold;'>"}, postTags = {"</span>"}, numberOfFragments = 5)
    )
    List<SearchHit<PostIndex>> findByPosDescription(String posDescription);


    @Highlight(
            //字段
            fields = {@HighlightField(name = "posName"),@HighlightField(name = "posDescription"),@HighlightField(name = "posKeyword")},
            parameters = @HighlightParameters(preTags = {"<span style='color:red;font-weight: bold;'>"}, postTags = {"</span>"}, numberOfFragments = 5)
    )
//    @Query("{\"bool\": {\"must\": [{\"term\": {\"jrId\": ?0}}, {\"bool\": {\"should\": [{\"match\": {\"posName\": {\"query\": \"?1\", \"analyzer\": \"ik_max_word\"}}}, {\"match\": {\"posDescription\": \"?2\"}}, {\"match\": {\"posKeyword\": \"?3\"}}]}}]}}")
//    List<SearchHit<PostIndex>> findByJrIdAndConditions(Integer jrId, String posName, String posDescription, String posKeyword);
    List<SearchHit<PostIndex>> findByJrIdAndPosNameOrPosDescriptionOrPosKeyword(Integer jrId, String posName, String posDescription, String posKeyword);


    @Highlight(
            //字段
            fields = {@HighlightField(name = "posDescription")},
            parameters = @HighlightParameters(preTags = {"<i style='color:red;font-weight: bold;'>"}, postTags = {"</i>"}, numberOfFragments = 5)
    )
    List<SearchHit<PostIndex>> findByIdOrPosDescription (String id, String posDescription);
//    List<SearchHit<PostIndex>> findByIdOrPosDescription (Integer id, String posDescription);


}
